﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TKToXML.Models;
using NHibernate.Mapping.ByCode.Conformist;
using NHibernate.Mapping.ByCode;

namespace TKToXML.Persistence.ClassMaps
{
    public class SinhVienMap : ClassMapping<SinhVien>
    {
        public SinhVienMap()
        {
            ComposedId(sv =>
                {
                    sv.Property(x => x.Id, x => x.Column("Id"));
                    sv.ManyToOne(x => x.Lop, map =>
                        {
                            map.Columns(c1 => c1.Name("LopId"), c2 => c2.Name("LopNam"));
                            map.Cascade(Cascade.All);
                        });
                    //sv.Property(x => x.Lop, map => 
                    //    {
                    //        map.Columns(c1 => c1.Name("LopId"), c2 => c2.Name("LopNam"));
                    //        //map.Type(typeof(Lop));
                    //    });
                });

            //Id(x => x.Id, 
            //    map => 
            //    { 
            //        map.Column("Id"); 
            //        map.Generator(Generators.Native); 
            //    });
            Property(x => x.Name, map => map.Column("Ten1"));
            //Property(x => x.LopId, map => { map.Column("LopId"); map.Insert(false); map.Update(false); });
            //Component<Lop>(x => x.Lop, map => map.ManyToOne<Lop>(l => l.Id));
            //Component<Guitar>(x => x.Guitar, map => map.ManyToOne<Guitar>(g => g.Id));
            ManyToOne(x => x.Lop, map =>
                {
                    //map.Class(typeof(Lop));
                    map.Columns(c1 => c1.Name("LopId"), c2 => c2.Name("LopNam"));
                    
                    //map.Column(a => a.Name("LopNam"));
                    //map.Column(a => a.Name("LopId")); 
                   
                    map.Cascade(Cascade.All);                    
                });
        }
    }
}
